<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图 -->
    <el-card class="box-card">
      <el-input style="width: 55%" placeholder="请输入内容" class="input-with-selete">
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>
    </el-card>
    <!-- 表格 -->
    <el-table :data="orders" border stripe>
      <el-table-column type="index" label="#"></el-table-column>
      <el-table-column prop="order_number" label="订单编号"></el-table-column>
      <el-table-column width="80px" prop="order_price" label="订单价格"></el-table-column>
      <el-table-column width="80px" prop="pay_status" label="是否付款">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.pay_status === 1">已付款</el-tag>
          <el-tag type="danger" v-else>未付款</el-tag>
        </template>
      </el-table-column>
      <el-table-column width="80px" prop="is_send" label="是否发货"></el-table-column>
      <el-table-column width="180px" prop="create_time" label="下单时间">
        <template slot-scope="scope">
          {{ scope.row.create_time | dateFormat }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="125px">
        <template>
          <el-button @click="showBox" size="mini" type="primary" icon="el-icon-edit"></el-button>
          <el-button @click="showExpressBox" size="mini" type="success" icon="el-icon-location-information"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
    :current-page="queryData.pagenum"
    :page-sizes="[3, 5, 10, 15]"
    :page-size="queryData.pagesize"
    layout="total, sizes, prev, pager, next, jumper"
    :total="total">
    </el-pagination>

  <el-dialog
    title="修改地址"
    :visible.sync="addressVisible"
    width="50%">
    <el-form :model="addressForm" :rules="addressFormRules" ref="addressFormRef" label-width="100px">
      <el-form-item label="省市区/县" prop="address1">
      <el-cascader
        v-model="addressForm.cascaderValue"
        :options="cityData">
        </el-cascader>
      </el-form-item>

      <el-form-item label="详细地址" prop="address2">
      <el-input v-model="addressForm.address2"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
    <el-button @click="addressVisible = false">取 消</el-button>
    <el-button type="primary" @click="addressVisible = false">确 定</el-button>
    </span>
  </el-dialog>

  <el-dialog
  title="查看物流进度"
  :visible.sync="expressDialogVisible"
  width="50%">
   <el-timeline>
    <el-timeline-item
      v-for="(item, index) in express"
      :key="index"
      :timestamp="item.time">
      {{ item.context }}
    </el-timeline-item>
  </el-timeline>
  <span slot="footer" class="dialog-footer">
    <el-button @click="expressDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="expressDialogVisible = false">确 定</el-button>
  </span>
</el-dialog>
  </div>
</template>

<script>
import cityData from './citydata.js'
console.log(cityData)
export default {
  data () {
    return {
      queryData: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orders: [],
      total: 0,
      addressVisible: false,
      expressDialogVisible: false,
      express: [],
      addressForm: {
        address1: [],
        address2: ''
      },
      addressFormRules: {
        address1: [
          { required: true, message: '请选择省市县', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请填写详细地址', trigger: 'blur' }
        ]
      },
      cityData: cityData
    }
  },
  created () {
    this.getOrders()
  },

  methods: {
    async getOrders () {
      const { data: res } = await this.$axios.get('orders', {
        params: this.queryData
      })
      if (res.meta.status !== 200) return this.$message.error('获取失败')
      this.$message.success('获取成功')
      this.orders = res.data.goods
      this.total = res.data.total
    },
    handleSizeChange (newSize) {
      this.queryData.pagesize = newSize
      this.getOrders()
    },
    handleCurrentChange (newPage) {
      this.queryData.pagenum = newPage
      this.getOrders()
    },
    async showExpressBox () {
      this.expressDialogVisible = true
      const { data: res } = await this.$axios.get('/kuaidi/1106975712662')

      if (res.meta.status !== 200) return this.$message.error('获取数据失败')
      this.express = res.data
    },
    showBox () {
      this.addressVisible = true
    }
  }
}
</script>
  import cityData from './'
<style scoped lang='less'>

</style>
